<?php 
session_start();
?>
<!DOCTYPE html>
<html>
   <head>
      <title>Bootstrap 模板</title>
	  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" charset="UTF-8" >
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link href="css/bootstrap.min.css" rel="stylesheet">
      <script src="js/jquery-1.11.1.min.js"></script>
      <script src="js/bootstrap.min.js"></script>
      <!--[if lt IE 9]>
         <script src="js/html5shiv.js"></script>
         <script src="js/respond.min.js"></script>
      <![endif]-->
   </head>
  <style>
  	.c{color:blue;}
  </style>
   <body>
     <nav class="navbar navbar-default">
    <div class="container">
    <div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed"
					data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
					<span class="sr-only">切换</span> <span class="icon-bar"></span> <span
						class="icon-bar"></span> <span class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="/th4.php">点餐系统		<?php 
									if(isset($_SESSION['yazi'])){
										print_r("<a href='logout.php'></a>");
											}else{
											header('Refresh:2;url=/deng1.php');
												die('<h3>你还未登录，请先登录</h3>');
													}
													?></a>
			</div>
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">订单管理 <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="dinglie.php">订单列表</a></li>
            <li><a href="dingji.php">订单记录</a></li>
          </ul>
        </li>
      </ul>
      <ul class="nav navbar-nav">
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">菜品管理 <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="jcp.php">添加菜品</a></li>
            <li><a href="cpl.php">菜品列表</a></li>
            <li class="divider"></li>
            <li><a href="jcx.php">添加菜品类型</a></li> 
            <li><a href="cplie.php">菜品类型列表</a></li>
          </ul>
        </li>
      </ul>
	  <ul class="nav navbar-nav">
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">餐桌管理 <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="jiazhuo.php">添加餐桌</a></li>
            <li><a href="canzl.php">餐桌列表 </a></li>
          </ul>
        </li>
      </ul>
	  <ul class="nav navbar-nav">
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">登录管理 <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#" data-toggle="modal" data-target="#aboutModal">关于点餐系统</a></li>
            <li><a href="xiugai.php">修改登录信息</a></li>
            <li><a href="#tui" data-toggle="modal">退出登录</a></li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
  <div class="modal fade" id="aboutModal" tabindex="-1" >
        	<div class="modal-dialog">
        		<div class="modal-content">
        			<div class="modal-header">
        				<button type="button" class="close" data-dismiss="modal">
        					<span>&times;</span><span class="sr-only">Close</span>
        				</button>
        				<h4 class="modal-title">关于皇子大酒店点餐系统</h4>
        			</div>
        			<div class="modal-body">
        			 本皇子大酒店，精选优质渣料，<br>
        			 选用上等地沟油，所有汤均用高级洗脚水熬制一天一夜而成。<br>
        			 各位顾客可放心点餐，我们还有优质的售后服务。<br>
        			 我们保证在顾客吃后负责挖坑，免除顾客的后顾之忧。<br>
        			 最后，感谢各位顾客的光临，我们的酒店因你而生辉。
        			 
        			</div>
        			<div class="modal-footer">
        				<button type="button" class="btn btn-warning" data-dismiss="modal">确定</button>
        			</div>
        		</div>
        	</div>
        </div>
        <div class="modal fade" id="tui" tabindex="-1" >
        	<div class="modal-dialog">
        		<div class="modal-content">
        			<div class="modal-header">
        				<button type="button" class="close" data-dismiss="modal">
        					<span>&times;</span><span class="sr-only">Close</span>
        				</button>
        				<h4 class="modal-title">确定退出登录</h4>
        			</div>
        			<div class="modal-body">
        			     你确定要退出登录吗？
        			</div>
        			<div class="modal-footer">
        				<a type="button" class="btn btn-default" href="tui.php">确定</a>
        				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        			</div>
        		</div>
        	</div>
        </div>
</nav>
				<?php
				@$dingId=$_REQUEST['dingid'];
				
				$pdo = new PDO ( 'mysql:dbname=can;charset=utf8', 'root' );
				$s = $pdo->prepare ( 'select *,ding.id as dingId from ding join zhuo on zhuo.id=zhuoId' );
				$s->execute ( );
				$b = $s->fetchAll ( PDO::FETCH_NAMED );
// 				var_dump($b);
				?>
				<?php
				$s = $pdo->prepare ( 'select *,ding.id as dingId from ding join zhuo on ding.id=:dingid' );
				$s->execute (array('dingid'=>$dingId));
				$d = $s->fetch ( PDO::FETCH_NAMED );
// 				var_dump($d);
				?>
				<?php 
				@$dingid=$_REQUEST['dingid'];
				$pdo = new PDO ( 'mysql:dbname=can;charset=utf8', 'root' );
				$s = $pdo->prepare ( 'select * from ding_cai as room
					join ding
						on room.dingId=ding.id
					join cai
						on room.caiId=cai.id' );
				$s->execute ( array (
						'dingid' => $dingid
				) );
				$Q = $s->fetchAll ( PDO::FETCH_NAMED );
// 				var_dump($Q);
				?>

<div class="container">
	<div class="row">
	<div class="col-sm-3 col-md-2 page-left">
	   <a class="btn btn-default btn-block" href="dinglie.php">订单列表</a>
	   <a class="btn btn-default btn-block" href="th4.php">返回首页</a>
	</div>
	<hr class="visible-xs-block" >
	<div class="col-sm-9 col-md-10">
                <div class="panel panel-primary">
            <div class="panel-heading">
                <h1 class="panel-title">
                    <span class="glyphicon glyphicon-th-list"></span>
                                                             历 史 订 单 列 表
                </h1>
            </div>
            <table class="table table-striped table-bordered table-hover">
                <tr>
                    <th>订单编号</th>
                    <th>餐桌号</th>
                    <th>菜品总数</th>
                    <th>菜品总价</th>
                    <th>下单时间</th>
                    <th>付款时间</th>
                    <th>订单状态</th>
                </tr>
                <?php for($c=0;$c<count($b);$c++){ ?>
                <tr>
                <?php
                $isExist=false;
                foreach ($Q as $item){
                	if($item['dingId']==$b[$c]['dingId']){
                		$isExist=true;
                		break;
                	}
                }
                	if($isExist){
                ?>
                <th><a href="?dingid=<?php echo $b[$c]['dingId']."&zhuoid=".$b[$c]['zhuoId']?>">mk45698-<?php echo $b[$c]['dingId']?></a></th>
                <th><?php echo $b[$c]['ming']?></th>
                <th><?php echo $b[$c]['shuliang']?></th>
                <th><?php echo $b[$c]['zongjia']?>	元</th>
                <th><?php echo $b[$c]['shijian']?></th>
                <th><?php echo $b[$c]['fu']?></th>
                <th>交易已完成</th>
                <?php }else {?>
                <?php }?>
                <?php }?>
                            </table>
        </div>
                <?php
				@$zhuoId=$_REQUEST['dingid'];
				
				$s = $pdo->prepare ( 'select *,ding.id as dingid from ding join zhuo on zhuo.id=zhuoId and ding.id=:dingid' );
				$s->execute (array('dingid'=>$zhuoId));
				$r = $s->fetch ( PDO::FETCH_NAMED );
// 				var_dump($r);
				?>
				<?php
		        $e=0;
		        @$dingid=$_REQUEST['dingid'];
		        @$id=$_REQUEST['zhuoid'];
				
				$s = $pdo->prepare ( 'select * from ding_cai as room
					join ding
						on room.dingId=ding.id
					join cai
						on room.caiId=cai.id
					join zhuo
						on room.zhuoId=zhuo.id
					where dingId=:dingid;' );
				$s->execute ( array (
					'dingid' => $dingid
					) );
				$v = $s->fetchAll ( PDO::FETCH_NAMED );
// 				var_dump($v);
				?>
        <div class="panel panel-primary">
            <div class="panel-heading">
            <?php if (empty($dingId)) {?>
                <h1 class="panel-title">
                    <span class="glyphicon glyphicon-th-list"></span>
                                                            点 选 "订单编号" 以 查 看 历 史 订 单 详 情
                </h1>
                <?php }else {?>
                <h1 class="panel-title">
                    <span class="glyphicon glyphicon-th-list"></span> 订单 <span style="color:red">mk45698-<?php echo $d['dingId']?></span> 的详情如下
                </h1>
            </div>
            <table class="table table-striped table-bordered table-hover">
            <tr>
            	<th>菜品图片</th>
            	<th>菜名</th>
            	<th>单价</th>
            	<th>数量</th>
            	<th>所属餐桌</th>
            </tr>
						<?php for($c=0;$c<count($v);$c++){ ?>
						<tr>
							<th><img alt="<?php echo $v[$c]['name']?>" style="height: 40px;" src="<?php echo $v[$c]['src']?>"></th>
							<th><?php echo $v[$c]['name']?></th>
							<th><span class="c"><?php echo $v[$c]['price']?>元</span></th>
							<th>x1</th>
							<?php $e+=$v[$c]['price']?>
							<th><?php echo $v[$c]['ming']?></th>
							
							</tr>
						<?php }?>
						<?php $n=$c;?>
						</table>
						<hr>
						<?php
						@$caiId=$_REQUEST['caiid'];
						@$dingId=$_REQUEST['dingid'];
// 						var_dump($id);
// 						var_dump($id);
// 						var_dump($jian);
// 						var_dump($n);
// 						var_dump($e);
// 						var_dump($dingId);
						
						@$confirm=$_REQUEST['confirm'];
						
						$params="?dingid=".$dingId.'&zhuoid='.$id.'&confirm=ok';
						if(!empty($confirm)){
							$s=$pdo->prepare('insert into ding_cai values(:dingid,:caiId,:zhuoid)');

							foreach ($v as $item) {
								if($s->execute(array('dingid'=>$dingId,'caiId'=>$item['caiId'],'zhuoid'=>$id))){
									?>
										<script type="text/javascript">
										location.href="/dingji.php";
									 	</script>
										<?php
								}
							}								
							
						}
						?>
						<div class="content">
						<div class="modal-body">
						<div class="row">
						<div class="caption text-right">所属餐桌在 <span style="color:blue"><?php echo $id; ?></span> 楼</div>
						<hr>
						<div class="caption text-right">总价是：<span style="color:blue"><?php echo $e;?></span> 元</div>
						<hr>
						<div class="caption text-right">下单时间：<span style="color:blue"><?php echo $r['shijian']?></span></div>
						<hr>
						<div class="caption text-right">交易完成时间：<span style="color:blue"><?php echo $r['fu']?></span></div>
						</div>
						</div>
						<hr>
									<div align="right">
									<img alt="" style="height: 30px;" src="png/2028.gif" />
									</div>
						</div>
						<?php }?>
            </div>
	</div>
</div>
</div>
</body>
</html>